/**
 * Created by novem on 2016/2/22.
 */
var grid;
define([
    "jquery",
    "IO",
    "bootbox"
], function($,IO,bootbox) {
    $(function () {

        //每列数据列性
        var columns = [
            {
                title: '课时ID',
                dataIndex: 'lecture_id',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].lecture_id + "</span>";
                }
            },
            {
                title: '课时序号',
                dataIndex: 'sequence',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].sequence + "</span>";
                }
            },
            {
                title: '课时(章节)名称',
                dataIndex: 'lecture_name',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].lecture_name + "</span>";
                }
            },
            {
                title: '课时视频',
                dataIndex: 'video_url',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].video_url + "</span>";
                }
            },
            {
                title: '评论数',
                dataIndex: 'comment_count',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].comment_count + "</span>";
                }
            },
            {
                title: '发布时间',
                dataIndex: 'create_date',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].create_date + "</span>";
                }
            },
            {
                title: '操作',
                dataIndex: 'action',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span><a href='javascript:void(0)' style='color: red;' class='delete' act_id='" +
                        data[datarow].lecture_id +
                        "'>删除</a>/<a href='/pte/editlecture?lecture_id="+
                        data[datarow].lecture_id+
                        "' style='color: orange;'>编辑</a>/<a href='/pte/course-test?course_id=" +
                         data[datarow].course_id +
                            "&lecture_id=" + data[datarow].lecture_id + "'>即时测试</a></span>";
                }
            },

        ];


        //数组初始化

        function dataInit() {
            grid = new Grid("/pte/api/lecture", $("#table_my_toast"), $("#paging_my_toast"), 1, 10, columns, get_input_param(), 10);

            //初始化
            grid.Init();
        }

        //获取输入框内容
        function get_input_param() {
            var course_id=$("#course_id").val();
            var param="course_id=" + course_id;
            return param;
        }
        dataInit();
        //查询
        $("#query").bind("click", function () {
            dataInit();
        });
    });
    //删除课时
    $(document).on("click",".delete",function(){
        var act_id=$(this).attr("act_id");
        if(act_id){
            bootbox.confirm("确定要删除该课时？",function(result){
                if(result) {
                    IO.get("act/lecture_delete",{act_id:act_id},function(d){
                        bootbox.alert(d.msg,function(){
                            if (d.code == 0) {
                                location.href = '/pte/lecture';
                            }
                        })
                    });
                }
            });
        }
    });

});